#!/bin/bash

JAR_NAME=$(basename $1)
APP_NAME=`echo ${JAR_NAME} | cut -d "." -f1`
PEM_PATH=/d/prod1.pem

echo APP_NAME: ${APP_NAME}

echo "------Upload Application("${APP_NAME}")------"
scp -o StrictHostKeyChecking=no $1 root@47.97.157.158:~/

echo "------Deploy Application("${APP_NAME}")------"
#ssh-add -k "${PEM_PATH}"
ssh root@47.97.157.158 \
"mkdir -p /home/admin/apps-jar/"${APP_NAME}" ;
cd /home/admin/apps-jar/"${APP_NAME}" ;
mv "$JAR_NAME" "$JAR_NAME"-backup ;
mv /root/"$JAR_NAME" ./ ;
cd ../ ;
sh app-start.sh "${APP_NAME}"/"${JAR_NAME}" >/dev/null 2>&1 ;
tailf -n 200 "${APP_NAME}"/~/swift/${APP_NAME%-exec}/logs/info.log"
